import {
	createStore
} from 'vuex'
import {
	hf,
	dxrequest,
	dxSToast
} from "@/util/index.js"
	
export const store = createStore({
	state: { //存放状态
		isboxrtt: 0, //播放的状态
		tetsdr: "",
		events:null,
		score_message:"",
		beijdrt:"",
		userInfo:null,
		cur_level_info:"",
		next_level_info:"",
		isjysd:false, // 是否禁音
		ttsText:"",
		isanzhu:false,
		xiaoxinr:""
	},
	mutations: {
		// 获取事件配置
		async getconfig(state) {
			if(state.events){
				return
			}
			const {
				data
			} = await dxrequest("api/child/event/config")
			state.events = data.events
			console.log(state.events)
		},
		// 事件上报  typestr= 进入对话 发送消息  点击宠物
		async fasongshijian(state,typestr){
			const pages = getCurrentPages()
			var page = pages[pages.length - 1];
			let event_code = ""
			state.events.map(a=>{
				if(a.event_name==typestr){
					event_code = a.event_code
				}
			})
			if(event_code){
				const {data} = await dxrequest("api/child/event/report",{
					"event_code": event_code, //事件类型，枚举见事件配置接口
					"event_path": page.$page.fullPath ,//时间
					 // debug:true
				},"post")
				state.score_message = data.score.change_score_tips
				state.beijdrt = data.score.score_message
				state.cur_level_info = data.level.cur_level_info
				state.next_level_info = data.level.next_level_info
				setTimeout(a=>{
					state.score_message = ""
				},2000)
				store.commit("getUserinfo")
			} 
		},
		// 获取用户信息
		async getUserinfo(state){
			const {data} = await dxrequest("api/child/user/profile")
			state.userInfo = data
		}
	}

})